#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from sqlalchemy import String
from sqlalchemy.dialects.mysql import LONGTEXT
from sqlalchemy.orm import Mapped, mapped_column

from backend.app.core.models.base import Base, id_key


class Tag(Base):
    """系统api"""

    __tablename__ = 'dbms_tag'

    id: Mapped[id_key] = mapped_column(init=False)
    code: Mapped[str] = mapped_column(String(50), unique=True, comment='tag代码')
    name: Mapped[str] = mapped_column(String(50), unique=True, comment='tag名称')
    status: Mapped[int] = mapped_column(default=1, comment='角色状态（0停用 1正常）')
    remark: Mapped[str | None] = mapped_column(LONGTEXT, comment='备注')
    instances: Mapped[list['Instance']] = relationship(  # noqa: F821
        init=False, secondary='dbms_instance_tag', back_populates='tags'
    )